package com.tanhua.dubbo.api.impl.mongo;

import com.tanhua.domain.mongo.Sound;
import com.tanhua.dubbo.api.mongo.SoundApi;
import org.apache.dubbo.config.annotation.Service;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

@Service
public class SoundApiImpl implements SoundApi {
    @Autowired
    private MongoTemplate mongoTemplate;
    /**
     * 保存音频文件
     *
     * @param sound
     */
    @Override
    public void save(Sound sound) {
        mongoTemplate.insert(sound);
    }

    /**
     * 查询一条数据
     *
     * @return
     */
    @Override
    public Sound findOne() {
        Sound sound = mongoTemplate.findOne(new Query(), Sound.class);
        return sound;
    }

    /**
     * 根据ID删除文档
     *
     * @param id
     */
    @Override
    public void deleteById(ObjectId id) {
        mongoTemplate.remove(id);
    }


}
